package com.xin.spring.project.util;

/**
 * 事务管理
 *
 * @author xinyue
 */
public class TransactionManager {

    ConnectionUtil connectionUtil;

    public void setConnectionUtil(ConnectionUtil connectionUtil) {
        this.connectionUtil = connectionUtil;
    }


    /**
     * 开启手动事务
     *
     * @throws Exception 异常
     */
    public void beginTransaction() throws Exception {
        connectionUtil.getCurrentThreadConn().setAutoCommit(false);
    }

    /**
     * 提交事务
     *
     * @throws Exception 异常
     */
    public void commit() throws Exception {
        connectionUtil.getCurrentThreadConn().commit();
    }

    /**
     * 回滚事务
     *
     * @throws Exception 异常
     */
    public void rollback() throws Exception {
        connectionUtil.getCurrentThreadConn().rollback();
    }
}
